package com.ll.xiaonew.system.modules.homes.controller;

import com.ll.xiaonew.commons.core.utils.PageUtils;
import com.ll.xiaonew.system.common.utils.R;
import com.ll.xiaonew.system.modules.homes.entity.HomePictureEntity;
import com.ll.xiaonew.system.modules.homes.service.HomePictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;




/**
 * 
 *
 * @author xiaonew
 * @email 2061996582@qq.com
 * @date 2023-04-06 18:24:38
 */
@RestController
@RequestMapping("homes/homepicture")
public class HomePictureController {
    @Autowired
    private HomePictureService homePictureService;

    /**
     * 查询当天需要展示的图片,如果有当天的显示当天，如果没有显示上一次的
     */
    @GetMapping("/showPicture")
    public List<HomePictureEntity> showPictureForToday(){
        List list = homePictureService.findPictureList();
        return list;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("homes:homepicture:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = homePictureService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("homes:homepicture:info")
    public R info(@PathVariable("id") Integer id){
		HomePictureEntity homePicture = homePictureService.getById(id);

        return R.ok().put("homePicture", homePicture);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("homes:homepicture:save")
    public R save(@RequestBody HomePictureEntity homePicture){
        homePicture.setCreateTime(new Date());
		homePictureService.save(homePicture);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("homes:homepicture:update")
    public R update(@RequestBody HomePictureEntity homePicture){
		homePictureService.updateById(homePicture);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("homes:homepicture:delete")
    public R delete(@RequestBody Integer[] ids){
		homePictureService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
